package cn.jetpiece.cloud.dict.api;

import cn.jetpiece.cloud.dict.api.model.params.CreateDictParam;
import cn.jetpiece.cloud.dict.api.model.params.UpdateDictParam;
import cn.jetpiece.cloud.dict.api.model.query.DictQuery;
import cn.jetpiece.cloud.dict.api.model.result.DictResult;
import cn.jetpiece.cloud.dict.api.model.result.DictTreeResult;
import cn.jetpiece.cloud.model.model.DictModel;
import cn.jetpiece.cloud.model.model.TableDictQuery;
import cn.jetpiece.cloud.model.model.TreeSelectResult;
import cn.jetpiece.cloud.model.page.PageResult;
import cn.jetpiece.cloud.model.response.Result;
import cn.jetpiece.cloud.resource.annotation.annotation.ApiResource;
import cn.jetpiece.cloud.resource.annotation.annotation.ScanResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * @author hancp
 * @version 1.0
 * @description: 字典
 * @date 2021/12/6 11:20
 */
@Api(tags = "字典")
@ApiResource
public interface DictApi {

    String SERVER_API = "/${jetpiece.common.path:common}";

    String API = "/dicts";


    /**
     * 字典分页列表
     *
     * @param sysDictQuery
     * @return
     */
    @ApiOperation(value = "字典分页列表", notes = "字典分页列表")
    @ScanResource(path = {SERVER_API + API, API}, method = RequestMethod.GET)
    Result<PageResult<DictResult>> queryPageList(@SpringQueryMap DictQuery sysDictQuery);

    /**
     * 获取树形字典数据
     *
     * @param sysDictQuery
     * @return
     */
    @ApiOperation(value = "获取树形字典数据", notes = "获取树形字典数据")
    @ScanResource(path = {SERVER_API + API + "/list-tree", API + "/list-tree"}, method = RequestMethod.GET)
    Result<List<DictTreeResult>> listTree(@SpringQueryMap DictQuery sysDictQuery);

    /**
     * 获取字典数据
     *
     * @param dictCode 表名,文本字段,code字段  | 举例：sys_user,realname,id
     * @return
     */
    @ApiOperation(value = "获取字典数据", notes = "获取字典数据")
    @ScanResource(path = {SERVER_API + API + "/dict-item/{dictCode}", API + "/dict-item/{dictCode}"}, method = RequestMethod.GET)
    Result<List<DictModel>> listDictItems(@PathVariable("dictCode") String dictCode);

    /**
     * 获取全部字典数据
     */
    @ApiOperation(value = "获取全部字典数据", notes = "获取全部字典数据")
    @ScanResource(path = {SERVER_API + API + "/list-all-dict-item", API + "/list-all-dict-item"}, method = RequestMethod.GET)
    Result<?> listAllDictItems();

    /**
     * 获取字典Text
     *
     * @param dictCode
     * @param key
     * @return
     */
    @ApiOperation(value = "获取字典Text", notes = "获取字典Text")
    @ScanResource(path = {SERVER_API + API + "/dict-item/{dictCode}/{key}", API + "/dict-item/{dictCode}/{key}"}, method = RequestMethod.GET)
    Result<String> getDictText(@PathVariable("dictCode") String dictCode, @PathVariable("key") String key);

    /**
     * 大数据量的字典表 走异步加载  即前端输入内容过滤数据
     *
     * @param dictCode
     * @param keyword
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "通过code异步加载字典", notes = "通过code异步加载字典")
    @ScanResource(path = {SERVER_API + API + "/dict-items/{dictCode}", API + "/dict-items/{dictCode}"}, method = RequestMethod.GET)
    Result<List<DictModel>> listByDictCode(@PathVariable("dictCode") String dictCode, @RequestParam(name = "keyword") String keyword, @RequestParam(value = "pageSize", required = false) Integer pageSize);

    /**
     * 根据字典code加载字典text 返回
     *
     * @param dictCode
     * @param keys
     * @param sign
     * @return
     */
    @ApiOperation(value = "根据字典code加载字典text", notes = "根据字典code加载字典text")
    @ScanResource(path = {SERVER_API + API + "/dict-item-texts/{dictCode}", API + "/dict-item-texts/{dictCode}"}, method = RequestMethod.GET)
    Result<List<String>> listDictText(@PathVariable("dictCode") String dictCode, @RequestParam(name = "key") String keys, @RequestParam(value = "sign", required = false) String sign);

    /**
     * 根据表名——显示字段-存储字段 pid 加载树形数据
     */
    @ApiOperation(value = "加载树形数据", notes = "加载树形数据")
    @ScanResource(path = {SERVER_API + API + "/list-dict-tree", API + "/list-dict-tree"}, method = RequestMethod.GET)
    Result<List<TreeSelectResult>> listTreeData(@RequestParam(name = "pid") String pid, @RequestParam(name = "pidField") String pidField, @RequestParam(name = "tableName") String tbname, @RequestParam(name = "text") String text, @RequestParam(name = "code") String code, @RequestParam(name = "hasChildField") String hasChildField, @RequestParam(name = "condition") String condition, @RequestParam(value = "sign", required = false) String sign);

    /**
     * 【APP接口】根据字典配置查询表字典数据
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "根据字典配置查询表字典数据", notes = "根据字典配置查询表字典数据")
    @ScanResource(path = {SERVER_API + API + "/list-data", API + "/list-data"}, method = RequestMethod.GET)
    Result<List<DictModel>> listTableData(@SpringQueryMap TableDictQuery query);

    /**
     * 新增
     *
     * @param sysDictParam
     * @return
     */
    @ApiOperation(value = "新增", notes = "新增")
    @ScanResource(path = {SERVER_API + API, API}, method = RequestMethod.POST)
    Result<DictResult> add(@RequestBody CreateDictParam sysDictParam);

    /**
     * 编辑
     *
     * @param sysDictParam
     * @return
     */
    @ApiOperation(value = "编辑", notes = "编辑")
    @ScanResource(path = {SERVER_API + API, API}, method = RequestMethod.PUT)
    Result<DictResult> edit(@RequestBody UpdateDictParam sysDictParam);

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除", notes = "删除")
    @ScanResource(path = {SERVER_API + API + "/{ids}", API + "/{ids}"}, method = RequestMethod.DELETE)
    Result<DictResult> delete(@PathVariable(name = "ids") String ids);

    /**
     * 刷新缓存
     *
     * @return
     */
    @ApiOperation(value = "刷新缓存", notes = "刷新缓存")
    @ScanResource(path = {SERVER_API + API + "/refresh-cache", API + "/refresh-cache"}, method = RequestMethod.GET)
    Result<String> refreshCache();

    /**
     * 查询被删除的列表
     *
     * @return
     */
    @ApiOperation(value = "查询被删除的列表", notes = "查询被删除的列表")
    @ScanResource(path = {SERVER_API + API + "/list-delete", API + "/list-delete"}, method = RequestMethod.GET)
    Result<List<DictResult>> deleteList();

    /**
     * 物理删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询被删除的列表", notes = "查询被删除的列表")
    @ScanResource(path = {SERVER_API + API + "/delete-physic/{id}", API + "/delete-physic/{id}"}, method = RequestMethod.DELETE)
    Result<String> deletePhysic(@PathVariable("id") String id);

    /**
     * 取回
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "取回", notes = "取回")
    @ScanResource(path = {SERVER_API + API + "/back/{id}", API + "/back/{id}"}, method = RequestMethod.PUT)
    Result<String> back(@PathVariable("id") String id);

    /**
     * 根据多个字典code查询多个字典项
     *
     * @param dictCodeList todo
     * @return key = dictCode ； value=对应的字典项
     */
    @ApiOperation(value = "多个字典code查询", notes = "多个字典code查询")
    @ScanResource(path = {SERVER_API + API + "/dict-items/dict-codes", API + "/dict-items/dict-codes"}, method = RequestMethod.PUT)
    Result<Map<String, List<DictModel>>> getManyDictItems(@RequestBody List<String> dictCodeList);

    /**
     * 【接口签名验证-排序】
     * 【给表单设计器的表字典使用】下拉搜索模式，有值时动态拼接数据
     *
     * @param dictCode
     * @param keyword
     * @param sign
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "接口签名验证-排序", notes = "接口签名验证-排序")
    @ScanResource(path = {SERVER_API + API + "/dict-items-sort/{dictCode}", API + "/dict-items-sort/{dictCode}"}, method = RequestMethod.GET)
    Result<List<DictModel>> loadDictOrderByValue(@PathVariable(name = "dictCode") String dictCode, @RequestParam(name = "keyword") String keyword, @RequestParam(value = "sign", required = false) String sign, @RequestParam(value = "pageSize", required = false) Integer pageSize);

    /**
     * 【接口签名验证】
     * 【JSearchSelectTag下拉搜索组件专用接口】
     * 大数据量的字典表 走异步加载  即前端输入内容过滤数据
     *
     * @param dictCode 字典code格式：table,text,code
     * @return
     */
    @ApiOperation(value = "接口签名验证", notes = "接口签名验证")
    @ScanResource(path = {SERVER_API + API + "load-dict-items/{dictCode}", API + "load-dict-items/{dictCode}"}, method = RequestMethod.GET)
    Result<List<DictModel>> loadDict(@PathVariable(name = "dictCode") String dictCode, @RequestParam(name = "keyword") String keyword, @RequestParam(value = "sign", required = false) String sign, @RequestParam(value = "pageSize", required = false) Integer pageSize);

}
